# -*- coding: utf-8 -*-
# @Time    : 2024/9/11 下午8:58
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : config.py
# @Software: PyCharm

import os
import configparser
from common.consts import CONFIG_PATH

class Config(object):
    """封装获取conf文件类"""
    def __init__(self,filename="config.ini"):
        self.cf = configparser.ConfigParser()
        self.log_path = os.path.join(CONFIG_PATH,filename)
        self.cf.read(self.log_path,encoding='utf-8')

    def get_conf(self,section, option):
        return self.cf.get(section,option)

    def set_conf(self, section, option, value):
        self.cf.set(section, option.value)
        with open(self.log_path, 'w+') as f:
            return self.cf.write(f)

    def add_section(self, section):
        self.cf.addsection(section)
        with open(self.log_path,'w+') as f:
            return self.cf.write(f)

    def get_runtime(self,option):
        return self.get_conf("runtime",option)

    def get_sever(self,option):
        return self.get_conf("server",option)

    def get_db_test(self,option):
        return self.get_conf("db_test",option)

    def get_email(self,option):
        return self.get_conf("email",option)



if __name__ == '__main__':
    cf=Config()
    x=cf.get_email("server")
    print(x)

